package com.jh.paymentchannel.payment;

import com.jh.paymentchannel.pojo.PaymentOrderStatistic;
import org.jetbrains.annotations.Contract;
import org.springframework.hateoas.ResourceAssembler;


/**
 * @author Fuchun
 * @since 1.0
 */
public abstract class PaymentAssemblers {

    @Contract(pure = true)
    public static ResourceAssembler<PaymentOrderStatistic, PosDTO> posResourceAssembler() {
        return PosResourceAssembler.DEFAULT;
    }

    public static PosDTO toDto(PaymentOrderStatistic pos) {
        return PosResourceAssembler.DEFAULT.toResource(pos);
    }

    private enum PosResourceAssembler implements ResourceAssembler<PaymentOrderStatistic, PosDTO> {
        DEFAULT;

        @Override
        public PosDTO toResource(PaymentOrderStatistic pos) {
            if (pos == null) return null;
            return new PosDTO(
                    pos.getId(),
                    pos.getUserId(),
                    pos.getOrderType(),
                    pos.getDealNumber(),
                    pos.getTotalAmount(),
                    pos.getTotalProfit(),
                    pos.getWeekOfYear(),
                    pos.getCreateTime()
            );
        }
    }

    private PaymentAssemblers() {}
}
